package com.ruoyi.center.demo.apiimpl;

import com.ruoyi.center.demo.api.DemoQueryApi;
import com.ruoyi.center.demo.api.dto.DemoDto;
import com.ruoyi.center.demo.service.DemoService;
import com.ruoyi.common.core.dto.CommonResultDto;
import com.ruoyi.common.core.web.page.PageResultDto;
import com.ruoyi.center.demo.convert.DemoConverter;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * demo查询api实现
 *
 * @author: wei.chen
 * @Date: 2022/2/15 16:17
 */
@RequestMapping("/v1/demo")
@RestController
@DubboService(group = "${dubbo.application.name}",protocol = "${dubbo.protocol.name}",
        version = "${dubbo.service.version}")
public class DemoQueryApiImpl implements DemoQueryApi {

    @Autowired
    private DemoService demoService;

    /**
     * 分页查询
     *
     * @param demoDto
     * @return
     */
    @Override
    public CommonResultDto<PageResultDto<DemoDto>> queryPage(@RequestParam("pageNum") Long pageNum
            , @RequestParam("pageSize") Long pageSize, @RequestBody DemoDto demoDto) {
        return CommonResultDto.success(demoService.queryPage(pageNum, pageSize, demoDto));
    }

    /**
     * 列表查询
     *
     * @param demoDto
     * @return
     */
    @Override
    public CommonResultDto<List<DemoDto>> queryList(@RequestBody DemoDto demoDto) {
        return CommonResultDto.success(DemoConverter.doList2DtoList(
                demoService.list(DemoConverter.buildWrapper(demoDto))));
    }

    /**
     * 详情查询
     *
     * @param id
     * @return
     */
    @Override
    public CommonResultDto<DemoDto> queryDetail(@PathVariable Long id) {
        return CommonResultDto.success(DemoConverter.do2Dto(
                demoService.getById(id)));
    }
}
